package cn.wh.mapping;

import cn.wh.transaction.TransactionFactory;
import lombok.Data;

import javax.sql.DataSource;

/**
 * @Author: wh
 * @CreateTime: 2023-01-17  10:01
 * @Description: 配置环境
 * @Version: 1.0
 */
public final class Environment {

    //环境id
    private final String id;

    //事物工厂
    private final TransactionFactory transactionFactory;

    //数据源
    private final DataSource dataSource;


    public Environment (String id,TransactionFactory transactionFactory,DataSource dataSource){
        this.id=id;
        this.transactionFactory=transactionFactory;
        this.dataSource=dataSource;
    }

    //构造器
    public static class Builder{
        private String id;
        private TransactionFactory transactionFactory;
        private DataSource dataSource;


        public Builder(String id){
            this.id=id;
        }

        public Builder transactionFactory(TransactionFactory transactionFactory) {
            this.transactionFactory = transactionFactory;
            return this;
        }

        public Builder dataSource(DataSource dataSource) {
            this.dataSource = dataSource;
            return this;
        }

        public Environment build(){
            return new Environment(this.id, this.transactionFactory, this.dataSource);
        }
    }


    public String getId() {
        return id;
    }

    public TransactionFactory getTransactionFactory() {
        return transactionFactory;
    }

    public DataSource getDataSource() {
        return dataSource;
    }
}
